home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11270 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP!!!!  --very important!!--
  5. Date: 22 Mar 1996 22:17:47 GMT
  6. Organization: OpenVision
  7. Message-ID: <4iv8ub$95t@spanky.pls.ov.com>
  8. References: <1996Mar21.000242.138161@forest>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 138161@forest, groy@forest.drew.edu (I can't think of a nickname) writes:
  13. >Please Help....
  14. >I need to get this program working... the function set_diff is supposed to 
  15. >find the differences between the two arrays (a[] and b[]) and put the 
  16. >differences(if any) in array c[]....
  17. >
  18. >int set_diff(int a[], int b[], int c[], int max) {
  19. >  int *first = a;
  20. >  int *second = b;
  21. >  int *third = c;
  22.  
  23. The above three pointers are pointers to *copies* of the input arrays.
  24. None of the original arrays are affected in any way.  If that was not
  25. your intent, then you need to reformulate your input list to be
  26. pointers to the arrays, and to adjust your function code accordingly.
  27.  
  28.         Fletcher.Glenn@ov.com
  29.  
  30.  
  31. >  int *endfirst = first + max;
  32. >  int *endsecond = second + max;
  33. >  int count=0;
  34. >  /*first compare each value of a to b and note the differences*/
  35. >
  36. >   for(first = a,second = b; first< endfirst, second<endsecond;
  37. >                         first++,second++){
  38. >           if (*first == *second)
  39. >             count =1;
  40. >
  41. >           if (count != 1){
  42. >           *third = *first;
  43. >           third++;     }   count =0;
  44. >        } /* end of for(first ... */
  45. >return count;
  46. >} /*end of set_diff */
  47. >int main () {
  48. >   int a[MAX], b[MAX], c[MAX * 2]; /*the three arrays */
  49. >   int count;
  50. >   int decide;
  51. >
  52. >   printf("Enter %i integers \n",MAX);
  53. >
  54. >   for (count = 0; count < MAX; count++)
  55. >       scanf("%i", &a[count]);
  56. >   printf("Enter %i more integers \n",MAX);
  57. >   for (count =0; count < MAX; count++)
  58. >       scanf("%i", &b[count]);
  59. >   decide =set_diff(a, b, c, MAX);
  60. >   /* now print the three arrays */
  61. >   printf("array a\n");
  62. >   for(count = 0; count < MAX; count++)
  63. >      printf("%2i ", a[count]);
  64. >   printf("\narray b\n");
  65. >   for(count = 0; count < MAX; count++)
  66. >      printf("%2i ", b[count]);
  67. >   if (decide != 1) {
  68. >   printf("\ndifference\n");
  69. >   for(count = 0; count < (MAX * 2); count++)
  70. >      printf("%2i ", c[count]); }
  71. >   printf("\n");
  72. >} /*end of main*/
  73. >
  74. >
  75. >
  76. >
  77. >
  78. >Thankyou for any help.. please hurry I am running out of time...
  79. >
  80. >
  81. >
  82. >Ps.. there are probbly two more programs on the way...
  83. >Greg Roy
  84. >Groy@drew.edu
  85. >
  86. >
  87.  
  88.  
  89.  
  90.  
  91.  
  92.